<?php
/**
 * Created by PhpStorm.
 * User: 王文凡<787802868@qq.com>
 * Date: 2016/9/2 0002
 * Time: 14:06
 */

namespace Admin\Controller;

use Common\Controller\AuthController;
use Think\Controller;

class WorksController extends AuthController
{
    //工单列表
    public function listers()
    {
        $counts= M('Workorder')->where("status !=%d",-1)->count();
        $page=page($counts,10,5);
        $list=M('Workorder')->alias("a")->field("a.*,b.nickname,b.company_name")
            ->join("sr_dealer_userinfo as b on a.formid=b.id")->where("a.status !=%d",-1)
            ->order("a.create_time DESC")
            ->limit($page->firstRow, $page->listRows)
            ->select();
        $this->assign('_list',$list);
        $this->assign('_page',$page->show());
        $this->assign('title','工单列表');
        $this->display();
    }
    //工单详情
    public function workDetail($wid='')
    {
        $re=M('Workorder')->alias("a")->field("a.*,b.nickname,b.company_name")
            ->join("sr_dealer_userinfo as b on a.formid=b.id")
            ->where("a.wid=%d",$wid)->find();
        $this->assign('re',$re);
        $this->assign('title','工单详情');
        $this->display();
    }
    //工单回复
    public function replyMsg()
    {
        if(IS_POST){
            if($_POST['tocontent']==''){
                $this->error('回复内容不能为空');
            }else{
                if($_POST['status']==0){
                    $_POST['status']=1;
                    $_POST['updae_time']=time();
                    if(M('Workorder')->where("wid=%d",$_POST['wid'])->save($_POST)){
                        $this->success('提交成功');
                    }else{
                        $this->error('提交失败');
                    }
                }else{
                    $this->error('不能回复此状态的工单');
                }
            }

        }
    }

}